var CommonUtil = new CommonUtil();

$(function() {
	queryItemList();
});

function toLogin() {
	location.href = CommonUtil.getRootPath() + '/sm-demo/page/login/login.html';
}

function toEditList(id) {
	location.href = CommonUtil.getRootPath() + '/sm-demo/page/list/editList.html?id='+id+'';
}

function queryItemList() {
    $.ajax({
        cache: true,
        type: 'POST',
		url : CommonUtil.getRootPath() + '/sm-demo/queryItemsList.action',
        data: JSON.stringify({}),
        dataType: 'JSON',
        contentType: 'application/json',
        async: true,
        beforeSend: function() {},
        error: function (data) {
        	console.log(data);
        },
        success: function (data) {
//        	alert(JSON.stringify(data));
        	if (data.status === 0 && data.result) {
        		queryList(data.result);
        	}
        }
        });
}

function queryList(data) {
	var str = '';
	data.forEach(function(v, i) {
		str += '<tr>';
		str += '<td><input type="checkbox" name="items_id" value="'+ v.id +'" /></td>';
		str += '<td>'+ v.name +'</td>';
		str += '<td>'+ v.price +'</td>';
		str += '<td>'+ fmtDate(new Date(v.createtime), 'yyyy-MM-dd hh:mm') +'</td>';
		str += '<td>'+ v.detail +'</td>';
		str += '<td><a class="updata_cus" onclick="toEditList('+v.id+')">修改</a><a class="delete_cus" onclick="deleteItem()">删除</a></td>';
		str += '</tr>';
	});
	$('#js_appent').empty();
	$('#js_appent').append(str);
}

function deleteItem() {
	
}
